home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / xmodem.doc < prev    next >
Encoding:
Text File  |  1985-06-03  |  7.9 KB  |  183 lines

  1.  
  2.  
  3.  
  4. MODEM PROTOCOL OVERVIEW  178 lines, 7.5K
  5.  
  6. 1/1/82 by Ward Christensen.  I will maintain a master copy of
  7. this.  Please pass on changes or suggestions via CBBS/Chicago
  8. at (312) 545-8086, or by voice at (312) 849-6279.
  9.  
  10. NOTE this does not include things which I am not familiar with,
  11. such as the CRC option implemented by John Mahr.
  12.  
  13. Last Rev: (none)
  14.  
  15. At the request of Rick Mallinak on behalf of the guys at
  16. Standard Oil with IBM P.C.s, as well as several previous
  17. requests, I finally decided to put my modem protocol into
  18. writing.  It had been previously formally published only in the
  19. AMRAD newsletter.
  20.  
  21.        Table of Contents
  22. 1. DEFINITIONS
  23. 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  24. 3. MESSAGE BLOCK LEVEL PROTOCOL
  25. 4. FILE LEVEL PROTOCOL
  26. 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  27. 6. PROGRAMMING TIPS.
  28.  
  29. -------- 1. DEFINITIONS.
  30. Name   Hex   ASCII  Ctrl+
  31. <soh>  01H    1     ^@
  32. <eot>  04H    4     ^D
  33. <ack>  05H    5     ^E
  34. <nak>  15H    21    ^U
  35. <can>   18H   24    ^X
  36.  
  37. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  38. Asynchronous, 8 data bits, no parity, one stop bit.
  39.  
  40.     The protocol imposes no restrictions on the contents of the
  41. data being transmitted.  No control characters are looked for
  42. in the 128-byte data messages.  Absolutely any kind of data may
  43. be sent - binary, ASCII, etc.  The protocol has not formally
  44. been adopted to a 7-bit environment for the transmission of
  45. ASCII-only (or unpacked-hex) data , although it could be simply
  46. by having both ends agree to AND the protocol-dependent data
  47. with 7F hex before validating it.  I specifically am referring
  48. to the checksum, and the block numbers and their ones-
  49. complement.
  50.     Those wishing to maintain compatibility of the CP/M file
  51. structure, i.e. to allow modemming ASCII files to or from CP/M
  52. systems should follow this data format:
  53.   * ASCII tabs used (09H); tabs set every 8.
  54.   * Lines terminated by CR/LF (0DH 0AH)
  55.   * End-of-file indicated by ^Z, 1AH.  (one or more)
  56.   * Data is variable length, i.e. should be considered a
  57.     continuous stream of data bytes, broken into 128-byte
  58.     chunks purely for the purpose of transmission.
  59.   * A CP/M "peculiarity": If the data ends exactly on a
  60.     128-byte boundary, i.e. CR in 127, and LF in 128, a
  61.     subsequent sector containing the ^Z EOF character(s)
  62.     is optional, but is preferred.  Some utilities or
  63.     user programs still do not handle EOF without ^Zs.
  64.   * The last block sent is no different from others, i.e.
  65.     there is no "short block".
  66.  
  67. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  68.  Each block of the transfer looks like:
  69. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  70.     in which:
  71. <SOH>       = 01 hex
  72. <blk #>     = binary number, starts at 01 increments by 1, and
  73.               wraps 0FFH to 00H (not to 01)
  74. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  75.               each bit complemented in the 8-bit block number.
  76.               Formally, this is the "ones complement".
  77. <cksum>     = the sum of the data bytes only.  Toss any carry.
  78.  
  79. -------- 4. FILE LEVEL PROTOCOL
  80.  
  81. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  82.  
  83.     All errors are retried 10 times.  For versions running with
  84. an operator (i.e. NOT with XMODEM), a message is typed after 10
  85. errors asking the operator whether to "retry or quit".
  86.     Some versions of the protocol use <can>, ASCII ^X, to
  87. cancel transmission.  This was never adopted as a standard, as
  88. having a single "abort" character makes the transmission
  89. susceptible to false termination due to an <ack> <nak> or <soh>
  90. being corrupted into a <can> and canceling transmission.
  91.     The protocol may be considered "receiver driven", that is,
  92. the sender need not automatically re-transmit, although it does
  93. in the current implementations.
  94.  
  95. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  96.     The receiver has a 10-second timeout.  It sends a <nak>
  97. every time it times out.  The receiver's first timeout, which
  98. sends a <nak>, signals the transmitter to start.  Optionally,
  99. the receiver could send a <nak> immediately, in case the sender
  100. was ready.  This would save the initial 10 second timeout.
  101. However, the receiver MUST continue to timeout every 10 seconds
  102. in case the sender wasn't ready.
  103.     Once into a receiving a block, the receiver goes into a
  104. one-second timeout for each character and the checksum.  If the
  105. receiver wishes to <nak> a block for any reason (invalid
  106. header, timeout receiving data), it must wait for the line to
  107. clear.  See "programming tips" for ideas
  108.     Synchronizing:  If a valid block number is received, it
  109. will be: 1) the expected one, in which case everything is fine;
  110. or 2) a repeat of the previously received block.  This should
  111. be considered OK, and only indicates that the receivers <ack>
  112. got glitched, and the sender re-transmitted; 3) any other block
  113. number indicates a fatal loss of synchronization, such as the
  114. rare case of the sender getting a line-glitch that looked like
  115. an <ack>.  Abort the transmission, sending a <can>
  116.  
  117. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  118.  
  119.     While waiting for transmission to begin, the sender has
  120. only a single very long timeout, say one minute.  In the
  121. current protocol, the sender has a 10 second timeout before
  122. retrying.  I suggest NOT doing this, and letting the protocol
  123. be completely receiver-driven.  This will be compatible with
  124. existing programs.
  125.     When the sender has no more data, it sends an <eot>, and
  126. awaits an <ack>, resending the <eot> if it doesn't get one.
  127. Again, the protocol could be receiver-driven, with the sender
  128. only having the high-level 1-minute timeout to abort.
  129.  
  130.  
  131. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  132.  
  133. Here is a sample of the data flow, sending a 3-block message.
  134. It includes the two most common line hits - a garbaged block,
  135. and an <ack> reply getting garbaged.  <xx> represents the
  136. checksum byte.
  137.  
  138. SENDER                                 RECEIVER
  139.                                times out after 10 seconds,
  140.                        <---            <nak>
  141. <soh> 01 FE -data- <xx>        --->
  142.                        <---            <ack>
  143. <soh> 02 FD -data- xx  --->    (data gets line hit)
  144.                        <---            <nak>
  145. <soh> 02 FD -data- xx  --->
  146.                        <---            <ack>
  147. <soh> 03 FC -data- xx  --->
  148.    (ack gets garbaged) <---            <ack>
  149. <soh> 03 FC -data- xx  --->            <ack>
  150. <eot>                  --->
  151.                        <---            <ack>
  152.  
  153. -------- 6. PROGRAMMING TIPS.
  154.  
  155. * The character-receive subroutine should be called with a
  156. parameter specifying the number of seconds to wait.  The
  157. receiver should first call it with a time of 10, then <nak> and
  158. try again, 10 times.
  159.   After receiving the <soh>, the receiver should call the
  160. character receive subroutine with a 1-second timeout, for the
  161. remainder of the message and the <cksum>.  Since they are sent
  162. as a continuous stream, timing out of this implies a serious
  163. like glitch that caused, say, 127 characters to be seen instead
  164. of 128.
  165.  
  166. * When the receiver wishes to <nak>, it should call a "PURGE"
  167. subroutine, to wait for the line to clear.  Recall the sender
  168. tosses any characters in its UART buffer immediately upon
  169. completing sending a block, to ensure no glitches were mis-
  170. interpreted.
  171.   The most common technique is for "PURGE" to call the
  172. character receive subroutine, specifying a 1-second timeout,
  173. and looping back to PURGE until a timeout occurs.  The <nak> is
  174. then sent, ensuring the other end will see it.
  175.  
  176. * You may wish to add code recommended by Jonh Mahr to your
  177. character receive routine - to set an error flag if the UART
  178. shows framing error, or overrun.  This will help catch a few
  179. more glitches - the most common of which is a hit in the high
  180. bits of the byte in two consecutive bytes.  The <cksum> comes
  181. out OK since counting in 1-byte produces the same result of
  182. adding 80H + 80H as with adding 00H + 00H.
  183.  
  184. cksum> comes
  185. out OK since counting in 1-byte produc